import 'dart:convert';
import 'dart:developer' as developer;

import 'package:flutter_mvvm/app/build_config.dart';

class Logger {
  static void log(String msg, [String tag = "Logger"]) {
    if (BuildConfig.DEBUG) {
      try {
        var object = json.decode(msg);
        msg = JsonEncoder.withIndent('  ').convert(object);
        final pattern = new RegExp('.{1,800}'); // 800 is the size of each chunk
        pattern.allMatches(msg).forEach((match) {
          developer.log(match.group(0));
        });
      } catch (e) {
        print('$tag: $msg');
      }
    }
  }
}
